"use strict";
cc._RF.push(module, '9ffe9uSA3RNVZSpDA6s8WEo', 'checkoutPanel');
// Script/checkoutPanel.ts

"use strict";
/**
 * 关卡界面
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Define_1 = require("./SdkTools/Define");
var gameNetWorkState_1 = require("./SdkTools/gameNetWorkState");
var gamePrefabMgr_1 = require("./SdkTools/gamePrefabMgr");
var gameShareAdsVideo_1 = require("./SdkTools/gameShareAdsVideo");
var PlayData_1 = require("./SdkTools/PlayData");
var storage_1 = require("./SdkTools/storage");
var TipsManager_1 = require("./SdkTools/TipsManager");
var Utils_1 = require("./SdkTools/Utils");
var TopUi_1 = require("./TopUi");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var checkoutPanel = /** @class */ (function (_super) {
    __extends(checkoutPanel, _super);
    function checkoutPanel() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.content = null;
        _this.content1 = null;
        _this.jiesuo = null;
        _this.pagenum = null;
        _this.moregamepanel = null;
        _this.jiesuoIndex = 0;
        _this.pageIndex = 0;
        _this.nowPageIndex = 0;
        _this.maxPageIndex = 0;
        _this.touchPos = null;
        _this.cellnum = 0;
        return _this;
    }
    checkoutPanel.prototype.onLoad = function () {
        this.jiesuo.active = !1;
        this.pageIndex = 0;
        this.nowPageIndex = 0;
        this.pagenum.string = '' + (this.pageIndex + 1);
        this.moregamepanel.active = !1;
        var levelnum = null;
        var _data = storage_1.default.Instance.getCheckPoint_diff();
        if (PlayData_1.default.Instance.gameType == PlayData_1.GameType.finddifference_zhaobutong) {
            this.cellnum = 15;
            levelnum = _data[3];
        }
        for (var index = 0; index < levelnum.length; index++) {
            var element = levelnum[index];
            if (element == 0) {
                this.nowPageIndex = Math.floor(index / this.cellnum);
                this.pageIndex = this.nowPageIndex;
                break;
            }
        }
        this.pagenum.string = '' + (this.nowPageIndex + 1);
        this.initUi();
    };
    checkoutPanel.prototype.start = function () {
        gameShareAdsVideo_1.default.Instance.chaPingAds_Show();
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            cc.find('moregame', this.node).active = !0;
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            cc.find('moregame', this.node).active = !1;
        }
    };
    checkoutPanel.prototype.letBtnClick = function () {
        this.pageIndex--;
        if (this.pageIndex < 0) {
            this.pageIndex = 0;
        }
        this.pagenum.string = '' + (this.pageIndex + 1);
        if (this.nowPageIndex != this.pageIndex) {
            this.nowPageIndex = this.pageIndex;
            this.initUi();
        }
    };
    checkoutPanel.prototype.rightBtnClick = function () {
        this.pageIndex++;
        if (this.pageIndex >= this.maxPageIndex) {
            this.pageIndex = this.maxPageIndex - 1;
        }
        this.pagenum.string = '' + (this.pageIndex + 1);
        if (this.nowPageIndex != this.pageIndex) {
            this.nowPageIndex = this.pageIndex;
            this.initUi();
        }
    };
    /**
     * 初始化ui
     */
    checkoutPanel.prototype.initUi = function () {
        if (PlayData_1.default.Instance.gameType == PlayData_1.GameType.finddifference_zhaobutong) {
            this.content1.removeAllChildren();
            this.cellnum = 15;
            this.maxPageIndex = Math.ceil(Define_1.default.maxCheckNum_huaijiu / this.cellnum);
            var _data = storage_1.default.Instance.getCheckPoint_diff();
            var levelnum = _data[3];
            var _loop_1 = function (ind) {
                var inn = (this_1.cellnum * this_1.nowPageIndex) + ind;
                var key = inn;
                //console.log('打印key=', key)
                var newitem = cc.instantiate(gamePrefabMgr_1.default.Instance.uiPre[gamePrefabMgr_1.uiPreName.check_item2]);
                newitem.parent = this_1.content1;
                newitem.name = '' + ind;
                newitem.on('click', this_1.itemClick, this_1);
                if (key < Define_1.default.maxCheckNum_huaijiu) {
                    newitem.active = !0;
                }
                else {
                    newitem.active = !1;
                }
                var num = cc.find('num_xiao', newitem).getComponent(cc.Label);
                var pic = cc.find('pic', newitem);
                var suo = cc.find('suo', newitem);
                var wenhao = cc.find('wenhao', newitem);
                num.string = '' + (key + 1);
                if (levelnum[key] == 1) {
                    suo.active = !1;
                    pic.active = !0;
                    wenhao.active = !1;
                    var sp_1 = pic.getComponent(cc.Sprite);
                    cc.resources.load('huaijiu/level' + (key + 1) + '/png' + (key + 1), cc.SpriteFrame, function (err, assert) {
                        if (err)
                            return console.error(assert);
                        sp_1.spriteFrame = assert;
                    });
                }
                else if (levelnum[key] == 0) {
                    suo.active = !1;
                    pic.active = !1;
                    wenhao.active = !0;
                    //newitem.color = cc.Color.GREEN
                }
                else {
                    suo.active = !0;
                    pic.active = !1;
                    wenhao.active = !1;
                }
            };
            var this_1 = this;
            for (var ind = 0; ind < this.cellnum; ind++) {
                _loop_1(ind);
            }
        }
    };
    checkoutPanel.prototype.itemClick = function (event) {
        console.log('item click=', event);
        if (PlayData_1.default.Instance.gameType == PlayData_1.GameType.finddifference_zhaobutong) {
            //let name = event.node.name
            var ind = Number(event.node.name);
            var _data = storage_1.default.Instance.getCheckPoint_diff();
            var levelnum = _data[3];
            var key = (this.cellnum * this.nowPageIndex) + ind;
            //console.log('打印数据', this.cellnum, this.nowPageIndex, ind, key)
            if (levelnum[key] == 0 || levelnum[key] == 1) {
                if (storage_1.default.Instance.getEnergy() <= 0) {
                    TipsManager_1.default.Instance.createTips('体力不足');
                    //console.log('体力不足')
                    var top = cc.find('Canvas/top');
                    var topsc = top.getComponent(TopUi_1.default);
                    topsc.openAddEngry();
                }
                else {
                    storage_1.default.Instance.setEnergy(storage_1.default.Instance.nowEnery - 1);
                    cc.director.emit('addengry');
                    cc.director.loadScene('GameScene');
                    PlayData_1.default.Instance.checkoutNum = key;
                    var randshu = Utils_1.default.getRangeRandom(0, 1);
                    if (gameNetWorkState_1.default.Instance.getShow() && randshu == 0) {
                        gameShareAdsVideo_1.default.Instance.motivational_Video_Show(function () {
                            storage_1.default.Instance.setTiShi(storage_1.default.Instance.getTiShi() + 1);
                            TipsManager_1.default.Instance.createTips('道具已发放');
                        }, function () { });
                    }
                }
            }
            else {
                this.jiesuo.active = !0;
                this.jiesuoIndex = ind;
            }
        }
    };
    /**
     * 解锁界面按钮
     * @param t
     * @param e
     */
    checkoutPanel.prototype.jiesuoBtnClick = function (t, e) {
        var _this = this;
        var self = this;
        if (e == 'no') {
            this.jiesuo.active = !1;
        }
        else if (e == 'ling') {
            var _data_1 = storage_1.default.Instance.getCheckPoint_diff();
            gameShareAdsVideo_1.default.Instance.motivational_Video_Show(function () {
                if (PlayData_1.default.Instance.gameType == PlayData_1.GameType.finddifference_zhaobutong) {
                    var kk = (_this.cellnum * _this.nowPageIndex) + self.jiesuoIndex;
                    _data_1[3][kk] = 0;
                    storage_1.default.Instance.setCheckPoint_diff(_data_1);
                    self.jiesuo.active = !1;
                    var item = cc.find('' + self.jiesuoIndex, self.content1);
                    cc.find('suo', item).active = !1;
                    cc.find('wenhao', item).active = !0;
                }
            }, function () { });
        }
    };
    // update (dt) {}
    checkoutPanel.prototype.closeBtn = function () {
        gameShareAdsVideo_1.default.Instance.showCustomAd(Define_1.CustomAdType.Shu);
        this.node.destroy();
    };
    /**
     * 打开原生矩阵广告
     */
    checkoutPanel.prototype.openMoreGamePanel = function () {
        this.moregamepanel.active = !0;
        gameShareAdsVideo_1.default.Instance.showCustomAd(Define_1.CustomAdType.More);
    };
    /**
     * 关闭更多游戏界面
     */
    checkoutPanel.prototype.closeMorePanelBtn = function () {
        this.moregamepanel.active = !1;
        gameShareAdsVideo_1.default.Instance.hideCustomAd(Define_1.CustomAdType.More);
    };
    __decorate([
        property(cc.Node)
    ], checkoutPanel.prototype, "content", void 0);
    __decorate([
        property(cc.Node)
    ], checkoutPanel.prototype, "content1", void 0);
    __decorate([
        property(cc.Node)
    ], checkoutPanel.prototype, "jiesuo", void 0);
    __decorate([
        property(cc.Label)
    ], checkoutPanel.prototype, "pagenum", void 0);
    __decorate([
        property(cc.Node)
    ], checkoutPanel.prototype, "moregamepanel", void 0);
    checkoutPanel = __decorate([
        ccclass
    ], checkoutPanel);
    return checkoutPanel;
}(cc.Component));
exports.default = checkoutPanel;

cc._RF.pop();